package com.fancyy.scm.base.http;

import android.content.Intent;

import com.fancyy.scm.BRApplication;
import com.fancyy.scm.bean.HttpMessage;
import com.fancyy.scm.util.ToastUtil;

/**
 * Created by any on 17/6/14.
 */

public class BRDataListener<T> implements DataListener<T> {

    public void onSuccess(T data) {

    }

    public void onFail(int status, String failMessage) {
        ToastUtil.showToast(BRApplication.getInstance().getApplicationContext(), failMessage);
//        if (status == 401) {
//            final Intent intent = BRApplication.getInstance().getPackageManager()
//                    .getLaunchIntentForPackage(BRApplication.getInstance().getPackageName());
//            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//            BRApplication.getInstance().startActivity(intent);
//        }
    }

    public void onMessage(HttpMessage<T> message) {
        if (message.status == 200) {
            onSuccess(message.data);
        } else {
            onFail(message.status, message.message);
        }
    }
}
